#!/bin/bash

leakport=$1
power_state=$3
portnum=${leakport#leakport}

leak_state=$(busctl get-property xyz.openbmc_project.leakdetector "/xyz/openbmc_project/state/leak/detector/LeakPort${portnum}_Big" xyz.openbmc_project.State.Leak.Detector State | awk -F'.' '{print $NF}' | tr -d '"')


if [ "$power_state" == "assert" ]; then
   # If power is asserted and leak state is Normal, turn on blue LED and turn off amber LED
   # Else do nothing control by the leak detector leakage service
   if [ "$leak_state" == "Normal" ]; then
      busctl set-property "xyz.openbmc_project.LED.GroupManager" "/xyz/openbmc_project/led/groups/${leakport}_amber" "xyz.openbmc_project.Led.Group" "Asserted" "b" "false"
      busctl set-property "xyz.openbmc_project.LED.GroupManager" "/xyz/openbmc_project/led/groups/${leakport}_blue" "xyz.openbmc_project.Led.Group" "Asserted" "b" "true"
   fi
elif [ "$power_state" == "deassert" ]; then
   busctl set-property "xyz.openbmc_project.LED.GroupManager" "/xyz/openbmc_project/led/groups/${leakport}_blue" "xyz.openbmc_project.Led.Group" "Asserted" "b" "false"
fi

exit 0
